﻿CREATE PROCEDURE [dbo].[TempStores_InsertDataFromTempSales]
AS
	INSERT INTO TempStores(CountryId, Code, Name, Region, City, Address, Phone, Fax, Format)
	SELECT rr.CountryId, StoreCode, StoreName, Region, City, Address, Phone, Fax, Format
	FROM TempArticleSales ts
	INNER JOIN RangeReviews rr on ts.RangeReviewId = rr.Id
	WHERE ts.Id IN
	(
		SELECT MIN(Id)
		FROM TempArticleSales
		GROUP BY RangeReviewId, StoreCode
	)
RETURN 0